package com.xinchuang.controller.targetSystem.icon;

import com.alibaba.fastjson.JSONObject;
import com.xinchuang.common.Result;
import com.xinchuang.common.ResultUtil;
import com.xinchuang.service.targetSystem.IconDataService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @ClassName IconDataController
 * @Description: TODO(写一段描述的话)
 * @Author zhangxuan
 * @Date 2022-08-23 16:29
 * @Verion V1.0
 */
@Api(value = "图片操作配置接口集", tags = {"图片操作配置接口集"})
@RestController
public class IconDataController {

    @Autowired
    private IconDataService iconDataService;

    private final String addIconData = "/iconData";

    private final String addIconDataPull = "/iconDataPull";

    @ApiOperation(value = "新增图片配置接口")
    @PostMapping(value = addIconData)
    public Result addIconData(
            @RequestBody JSONObject jsonObject
            ) {
        String iconUrl = jsonObject.getString("iconUrl");
        if (StringUtils.isBlank(iconUrl)) {
            return ResultUtil.error(500, "上传不成功，请先确认图片");
        }
        return iconDataService.addIconData(iconUrl);
    }

    @ApiOperation(value = "删除图片配置接口")
    @DeleteMapping(value = addIconData)
    public Result delIconData(
            @RequestParam(value = "id") String id
    ) {
        return iconDataService.delIconData(id);
    }

    @ApiOperation(value = "查询图片配置接口")
    @GetMapping(value = addIconData)
    public Result selectIconDataList(
            @RequestParam(value = "id", required = false) String id
    ) {
        return iconDataService.selectIconDataList(id);
    }

    @ApiOperation(value = "查询图片配置下拉接口")
    @GetMapping(value = addIconDataPull)
    public Result selectIconDataPull() {
        return iconDataService.selectIconDataPull();
    }

}